package com.xjscrm.server.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author mingyang.chen create in 2024/5/8 18:44
 */
public class DelayTopicHolder {

    public static final List<String> delayTopic = new ArrayList<>();
    private static AtomicInteger index = new AtomicInteger(0);

    public static void addDelayTopic(String topic) {
        delayTopic.add(topic);
    }

    public static String getNextServer() {
        int current = index.getAndIncrement();
        int i = current % delayTopic.size();
        return delayTopic.get(i);
    }

    public static void main(String[] args) {
        DelayTopicHolder.addDelayTopic("topic1");
        DelayTopicHolder.addDelayTopic("topic2");
        DelayTopicHolder.addDelayTopic("topic3");

        for (int i = 0; i < 99; i++) {
            System.out.println(DelayTopicHolder.getNextServer());
        }
    }
}
